home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / deq.arc / DEQ.C next >
Text File  |  1985-09-20  |  4KB  |  93 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*   deq.c- selective delete; queries for each file to delete
  3.  *          Uses C86 filedir() subroutine to return matching directory
  4.  *          entries, queries to delete each file separately: Yes or No;
  5.  *          Entry of G ends polling, begins automatic deletion (abort with
  6.  *                    any keystroke).  Quit ends program.
  7.  *   Copyright 1985 Walter Borys. No liability or guarantee for usage.
  8.  *   Distributed as Freeware for utility or educational purposes
  9.  *              only; not to be sold under any circumstances. 
  10.  *   Name and copyright notice may not be altered or removed.
  11.  */
  12. /*--------------------------------------------------------------------------*/
  13. #include "stdio.h"
  14. main(ac,av)
  15.     int ac;
  16.     char *av[];
  17.     {
  18.     extern char *filedir();         /* pointer to directory strings */
  19.     char *filptr, *next;            /* pointer to current, next file*/
  20.     char delfile[20];               /* filename with drive          */
  21.     char *driveptr;                 /* pointer to drive with files  */
  22.     int n,killall,reply,attrib;
  23.     int bdos();
  24.     static *hlptxt[]={
  25. "DEQ Selective Delete Program Usage:  dq [d:]filnam.ext\n\n",
  26. "  Program will poll to delete each matching file: /Y/N/G/Q\n",
  27. "    'Y'ES or 'N'O to delete, 'G'O to delete without polling, or 'Q'UIT\n",
  28. "    `G' process may be halted by hitting any key.\n",
  29. "    * and ? wildcards are supported, pathes are not.\n",
  30. "\nDEQ Version 1.1  Copyright Walt Borys 1985. Distributed as Freeware\n"};
  31. /*--------------------------------------------------------------------------*/
  32.  
  33.     if (ac != 2)    /* print help message if no files specified */
  34.         {
  35.         for (n=0;n<6;n++)
  36.             printf(hlptxt[n]);
  37.         exit(0);
  38.         }
  39.  
  40.     strncpy(delfile,av[1],20);              /* get file spec */
  41.     attrib = 0;                             /* normal file attributes */
  42.     for (n=0;n<strlen(delfile);n++)         /* check for pathes       */
  43.         if (delfile[n] == 0134)
  44.             abort("Sorry- don't do pathes \n");
  45.  
  46.     if (delfile[1]==':')                    /* another disk */
  47.         driveptr=&delfile[2];
  48.     else
  49.         driveptr=&delfile[0];
  50.  
  51.     filptr = filedir(delfile,attrib);       /* directory string returned */
  52.  
  53.     if (filptr == NULL)
  54.         {
  55.         printf("No match for files %s found \n",delfile);
  56.         exit(1);
  57.         }
  58.  
  59.     killall = reply = 0;
  60.     for (next = filptr; *next != NULL; next = next + strlen(next) + 1)
  61.         {
  62.         strcpy(driveptr,next);                   /* next file to delete */
  63.  
  64.         if (!killall)   /* query next delete, unless in delete all mode  */
  65.             {
  66.             while (bdos(11)&01)     /* flush typeahead */
  67.                 bdos(7);
  68.             do  {             /* main query iteration- loop thru files  */
  69.                 printf(" Delete '%-15.15s'? (Y/N/G/Q) *",delfile);putchar(-1);
  70.                 reply = toupper(bdos(7) &0177);     /* keystroke reply  */
  71.                 if (reply=='\03')                   /* convert ^C to Q  */
  72.                     reply = 'Q';
  73.                 printf("%c\n",reply);               /* echo reply       */
  74.                 } while (reply!='Y'&&reply!='N'&&reply!='G'&&reply!='Q');
  75.             }
  76.  
  77.         if (reply == 'G') /* full delete, toggle reply to permanent Y  */
  78.             killall = reply = 'Y';
  79.  
  80.         if (reply == 'Y')                        /* yes, delete file */
  81.            unlink(delfile);
  82.  
  83.         if (reply == 'Q')                        /* quit */
  84.             break;
  85.  
  86.         if (killall)         /* tell what is automatically being deleted */
  87.             printf("   Deleting '%-15.15s'\n",next);
  88.  
  89.         if (killall && bdos(11)&01)         /* interrupt the full delete */
  90.             killall = 0;                           /* go back to polling */
  91.         }        
  92.     free(filptr);                           /* de allocate memory  */
  93.     }